#include<stdio.h>
#define vn 20
typedef struct WG
{
	int vs[vn];
	int as[vn][vn];
	int vnum,anum;
}wg;
typedef struct NET
{
	int vs[vn];
	int as[vn][vn];
	int vnum,anum;
}net;
void create_wg(wg * G)
{
	int i,j,k;
	scanf("%d%d",&G->vnum ,&G->anum );
	for(i=0;i<G->vnum ;i++)
		scanf("%d",&G->vs [i]);
	for(i=0;i<G->vnum ;i++)
		for(j=0;j<G->vnum ;j++)
			G->as [i][j]=0;
	for(k=0;k<G->anum ;k++)
	{
		scanf("%d%d",&i,&j);
		G->as [i-1][j-1]=1;
		G->as [j-1][i-1]=1;
	}
}
void display_wg(wg G)
{
	int i,j;
	printf("vs is:\n");
	for(i=0;i<G.vnum ;i++)
		printf("%d",G.vs [i]);
	printf("\n");
	printf("as is:\n");
	for(i=0;i<G.vnum ;i++)
	{
		for(j=0;j<G.vnum ;j++)
			printf("%4d",G.as [i][j]);
		printf("\n");
	}
}
void df_wg(wg G,int v,int visited[])
{
	printf("%d",G.vs [v]);
	visited[v]=1;
	for(int w=0;w<G.vnum ;w++)
		if(G.as [v][w]!=0&&visited[w]==0)
			df_wg(G,w,visited);
}
#define max 20
typedef struct ANODE
{
	int a;
	struct ANODE * nexta;
}anode;
typedef struct VNODE
{
	int v;
	anode * firsta;
}vnode;
typedef struct LING
{
	vnode alist[max];
	int vnum,anum;
}ling;
void create_ling(ling * G)
{
	int i,j,k;
	scanf("%d%d",&G->vnum ,&G->anum );
	for(i=0;i<G->vnum ;i++)
	{
		scanf("%d",&G->alist[i].v );
		G->alist [i].firsta =NULL;
	}
	for(k=0;k<G->anum ;k++)
	{
		scanf("%d%d",&i,&j);
		anode * p=NULL;
		p=new anode;
		p->a =j-1;
		p->nexta =G->alist [i-1].firsta ;
		G->alist [i-1].firsta =p;
	}
}
void display_ling(ling G)
{
	int i,j;
	anode * p=NULL;
	printf("ling is:\n");
	for(i=0;i<G.vnum ;i++)
	{
		printf("%4d",i);
		printf("%4d",G.alist [i].v );
		if(G.alist [i].firsta ==NULL)
			printf("#\n");
		else
		{
			p=G.alist [i].firsta ;
			while(p)
			{
				printf("%4d-->",p->a );
				p=p->nexta ;
				printf("#\n");
			}
		}
	}
}
void df_ling(ling G,int v,int visited[])
{
	printf("%d",G.alist [v].v );
	visited[v]=1;
	anode * p=NULL;
	int w;
	p=G.alist [v].firsta ;
	while(p)
	{
		w=p->a ;
		if(visited[w]==0)
			df_ling(G,w,visited);
		p=p->nexta ;
	}
}
int main()
{
	ling g;
	ling *pg;
	pg=&g;
	create_ling(pg);
	display_ling(g);
	return 0;
}